package com.geniusk.system.service.impl;

import com.geniusk.common.enums.ResponseType;
import com.geniusk.common.exception.GraceException;
import com.geniusk.system.model.mapper.RoleMapper;
import com.geniusk.system.model.pojo.Role;
import com.geniusk.system.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public List<Role> selectAllRole() {
        return roleMapper.selectAllRole();
    }

    @Override
    public Role selectRoleById(Long roleId) {
        return roleMapper.selectRoleById(roleId);
    }

    @Override
    public List<Role> selectRoleByPage(Role role) {
        return roleMapper.selectRoleByPage(role);
    }

    @Override
    public boolean selectRoleIsExist(Long[] roleIds) {
        return roleMapper.selectRoleIsExistByRoleIds(roleIds);
    }

    @Override
    public boolean selectRoleNameIsExist(String roleName){
        return roleMapper.selectRoleIsExistByRoleName(roleName);
    }

    @Override
    public int insertRole(Role role) {
        return roleMapper.insertRole(role);
    }

    @Override
    public int updateRole(Role role) {
        return roleMapper.updateRole(role);
    }

    @Override
    public int deleteRoleByIds(Long[] ids) {
        if (roleMapper.roleCanDeleteOrNot(ids)) {
            GraceException.display(ResponseType.ASSOCIATION_EXIST_ERROR);
        }
        return roleMapper.deleteRoleByIds(ids);
    }
}
